package jdbc;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.Scanner;

public class JDBCDemo12 {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        System.out.println("请输入用户名:");
        String userName = scan.nextLine();
        try (Connection connection = DBUtil.getConnection();){
            String sql = "DELETE FROM userinfo WHERE username = ?";
            PreparedStatement ps = connection.prepareStatement(sql);
            ps.setString(1, userName);
            int num = ps.executeUpdate();
            System.out.println(num > 0 ? "删除成功" : "用户名不存在");
        } catch (SQLException e) {
            e.printStackTrace();
        }

    }
}
